<?php

namespace App\Containers\AppSection\Profile\Tasks;

use App\Containers\AppSection\Profile\Data\Repositories\ProfileRepository;
use App\Containers\AppSection\Profile\Models\Profile;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class ChangeProfilePhoneTask extends Task
{
    protected ProfileRepository $repository;

    public function __construct(ProfileRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run($id, $phone): Profile
    {
        try {
            return $this->repository->update(['phone' => $phone], $id);
        } catch (Exception $exception) {
            throw new UpdateResourceFailedException();
        }
    }
}
